package com.khaled.protclass.model.util;

import java.util.ArrayList;

public class UtilAminoAcids
{
	private final String AMINO_ALA = "ALA";

	private final String AMINO_CYS = "CYS";

	private final String AMINO_ASP = "ASP";

	private final String AMINO_GLU = "GLU";

	private final String AMINO_PHE = "PHE";

	private final String AMINO_GLY = "GLY";

	private final String AMINO_HIS = "HIS";

	private final String AMINO_ILE = "ILE";

	private final String AMINO_LYS = "LYS";

	private final String AMINO_LEU = "LEU";

	private final String AMINO_MET = "MET";

	private final String AMINO_ASN = "ASN";

	private final String AMINO_PRO = "PRO";

	private final String AMINO_GLN = "GLN";

	private final String AMINO_ARG = "ARG";

	private final String AMINO_SER = "SER";

	private final String AMINO_THR = "THR";

	private final String AMINO_VAL = "VAL";

	private final String AMINO_TRP = "TRP";

	private final String AMINO_TYR = "TYR";

	// ///////////////////////////////////////////////////

	protected final String A = "A";

	protected final String C = "C";

	protected final String D = "D";

	protected final String E = "E";

	protected final String F = "F";

	protected final String G = "G";

	protected final String H = "H";

	protected final String I = "I";

	protected final String K = "K";

	protected final String L = "L";

	protected final String M = "M";

	protected final String N = "N";

	protected final String P = "P";

	protected final String Q = "Q";

	protected final String R = "R";

	protected final String S = "S";

	protected final String T = "T";

	protected final String V = "V";

	protected final String W = "W";

	protected final String Y = "Y";

	private ArrayList<String> aminoNames = null;

	private ArrayList<String> aminoSymbols = null;

	private ArrayList<String> aminoDipeptides = null;

	private static UtilAminoAcids aminoAcids;

	public UtilAminoAcids()
	{
	}

	private void fillAminoDipeptides()
	{
		this.aminoDipeptides = new ArrayList<String>();

		for (String amino1 : this.getAminoSymbols())
		{
			for (String amino2 : this.getAminoSymbols())
			{
				aminoDipeptides.add(amino1 + amino2);
			}
		}
	}

	private void fillAminoSymbols()
	{
		this.aminoSymbols = new ArrayList<String>();

		this.aminoSymbols.add(A);
		this.aminoSymbols.add(C);
		this.aminoSymbols.add(D);
		this.aminoSymbols.add(E);
		this.aminoSymbols.add(F);
		this.aminoSymbols.add(G);
		this.aminoSymbols.add(H);
		this.aminoSymbols.add(I);
		this.aminoSymbols.add(K);
		this.aminoSymbols.add(L);
		this.aminoSymbols.add(M);
		this.aminoSymbols.add(N);
		this.aminoSymbols.add(P);
		this.aminoSymbols.add(Q);
		this.aminoSymbols.add(R);
		this.aminoSymbols.add(S);
		this.aminoSymbols.add(T);
		this.aminoSymbols.add(V);
		this.aminoSymbols.add(W);
		this.aminoSymbols.add(Y);
	}

	private void fillAminoNames()
	{
		this.aminoNames = new ArrayList<String>();

		this.aminoNames.add(AMINO_ALA);
		this.aminoNames.add(AMINO_CYS);
		this.aminoNames.add(AMINO_ASP);
		this.aminoNames.add(AMINO_GLU);
		this.aminoNames.add(AMINO_PHE);
		this.aminoNames.add(AMINO_GLY);
		this.aminoNames.add(AMINO_HIS);
		this.aminoNames.add(AMINO_ILE);
		this.aminoNames.add(AMINO_LYS);
		this.aminoNames.add(AMINO_LEU);
		this.aminoNames.add(AMINO_MET);
		this.aminoNames.add(AMINO_ASN);
		this.aminoNames.add(AMINO_PRO);
		this.aminoNames.add(AMINO_GLN);
		this.aminoNames.add(AMINO_ARG);
		this.aminoNames.add(AMINO_SER);
		this.aminoNames.add(AMINO_THR);
		this.aminoNames.add(AMINO_VAL);
		this.aminoNames.add(AMINO_TRP);
		this.aminoNames.add(AMINO_TYR);
	}

	public static UtilAminoAcids getInstance()
	{
		if (aminoAcids == null)
		{
			aminoAcids = new UtilAminoAcids();
		}
		return aminoAcids;
	}

	public ArrayList<String> getAminoAcidNames()
	{
		if (this.aminoNames == null)
		{
			fillAminoNames();
		}

		return this.aminoNames;
	}

	public ArrayList<String> getAminoSymbols()
	{
		if (this.aminoSymbols == null)
		{
			fillAminoSymbols();
		}

		return aminoSymbols;
	}

	public ArrayList<String> getAminoDipeptides()
	{
		if (this.aminoDipeptides == null)
		{
			fillAminoDipeptides();
		}
		return aminoDipeptides;
	}

	public boolean validateProteinSequence(String proteinSequence)
	{
		String goodChars = "ACDEFGHIKLMNPQRSTVWYacdefghiklmnpqrstvwy \r\n";

		for (int i = 0; i < proteinSequence.length(); i++)
		{
			if (goodChars.indexOf(proteinSequence.charAt(i)) == -1) { return false; }
		}
		return true;
	}

}
